package com.briup.cms.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.cms.dao.ArticleDao;
import com.briup.cms.domain.Article;
import com.briup.cms.domain.param.ArticleQueryParam;
import com.briup.cms.domain.vo.ArticleVo;
import com.briup.cms.service.IArticleService;
import com.briup.cms.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author briup
 * @since 2023-03-09
 */
@Api("文章模块")
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    IArticleService articleService;
    @Autowired
    ArticleDao articleDao;

    @ApiOperation("新增或修改文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "article",value = "新增或修改的文章")
    })
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Article article){
        articleService.saveOrUpdate(article);
        return Result.success();
    }

    @ApiOperation("删除文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "删除文章的id")
    })
    @GetMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        articleService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("查询文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param",value = "查询条件")
    })
    @PostMapping("/query")
    public Result query(ArticleQueryParam param){
        IPage<Article> query = articleService.query(param);
        return Result.success(query);
    }

    @ApiOperation("根据id查询文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "文章id")
    })
    @GetMapping("/queryById")
    public Result queryById(Long id){
        ArticleVo articleVo = articleService.queryById(id);
        return Result.success(articleVo);
    }
}


